﻿<%@ Page Language="C#" MasterPageFile="~/WebSite.Master" AutoEventWireup="true" 
CodeBehind="UserAppInfo.aspx.cs" Inherits="RN.ERP.Web.Manage.UserAppInfo" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../Styles/skins/blue/css/style_msg.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../Scripts/jquery.min.js"></script>
    <script type="text/javascript" src="../Scripts/ligerUI/js/ligerui.min.js"></script>
    <script type="text/javascript" src="../Scripts/ligerUI/js/plugins/ligerGrid.js"></script>
    <script type="text/javascript" src="../Scripts/ligerUI/js/plugins/ligerLayout.js"></script>
    <script type="text/javascript" src="../Scripts/ligerUI/js/plugins/ligerTextBox.js"></script>
    <script src="../Scripts/ligerUI/js/ligerui.all.js" type="text/javascript"></script>

    <script type="text/javascript" language="javascript">
        $(function () {
            var layout = $("#layout").ligerLayout({
                bottomHeight: $(window).height() - 390,//270,
                heightDiff: -6
            });

            var selectedUserID, selectedRoleID;
            var roleGrid, corpGrid, sysGrid;


            //查询按钮
            $("#btn").ligerButton(
            {
                text: '查询',
                click: loadCorpGrid
            });
            function loadCorpGrid() {
                $.ajax({
                    type: 'get',
                    cache: false,
                    dataType: 'json',
                    url: '../handlers/AuthorityHandler.ashx?act=getusers&corpName=' + encodeURI($('#txtCorpName').val()) + '&r=' + Math.random(),
                    success: function (result) {
                        corpGrid.set('data', { Rows: result });
                    }
                });
                $.ajax({
                    type: 'get',
                    cache: false,
                    dataType: 'json',
                    url: '../handlers/AuthorityHandler.ashx?act=getsys&r=' + Math.random(),
                    success: function (result) {
                        sysGrid.set('data', { Rows: result });
                    }
                });
            }


            //用户列表
            corpGrid = $("#corpgrid").ligerGrid({
                columns:
                [
                { display: '企业名称', name: 'CorpName', width: "16%", align: 'left' },
                { display: '地址', name: 'Address', width: "22%", align: 'left' },
                { display: '地区编号', name: 'AreaCode', width: "6%", align: 'center' },
                { display: '联系人', name: 'LinkMan1', width: "6%", align: 'center' },
                { display: '主项资质', name: 'QualificationLevel', width: "13%", align: 'left' },
                { display: '经营范围', name: 'BussinessArea', width: "29%", align: 'left' },
                { display: '订单信息  ', isAllowHide: false, width: "6%",
                    render: function (rowdata) {
                        var html = '<a href="UserCAInfo.aspx?CorpUserGuid=' + rowdata.CorpUserGuid + '" target="_blank">查看</a>';
                        return html;
                    }
                }
                ], showToggleColBtn: false, width: '100%', height: 300, rowHeight: 20, fixedCellHeight: true,
                columnWidth: 100, frozen: false, checkbox: false, rownumbers: true,
                data: []
            });
            $.ajax({
                type: 'get',
                cache: false,
                dataType: 'json',
                url: '../handlers/AuthorityHandler.ashx?act=getusers&corpName=' + encodeURI($('#txtCorpName').val()) + '&r=' + Math.random(),
                success: function (result) {
                    corpGrid.set('data', { Rows: result });
                }
            });
            corpGrid.bind('SelectRow', function (rowdata) {
                var CorpUserGuid = rowdata.CorpUserGuid;
                $.ajax({
                    type: 'get',
                    cache: false,
                    dataType: 'json',
                    url: '../handlers/AuthorityHandler.ashx?act=getsys&corpUserGuid=' + CorpUserGuid + '&r=' + Math.random(),
                    success: function (result) {
                        sysGrid.set('data', { Rows: result });
                    }
                });
            });



            //系统列表
            sysGrid = $("#sysgrid").ligerGrid({
                columns:
                [
                { display: '系统ID', name: 'AppId', width: "14%", align: 'center' },
                { display: '系统名称', name: 'Title', width: 450, align: 'left' }
                ], showToggleColBtn: false, width: '100%', height: 240, rowHeight: 20, fixedCellHeight: true,
                columnWidth: 100, frozen: false, rownumbers: true, checkbox: true, isChecked: f_isChecked,
                data: []
            });
            $.ajax({
                type: 'get',
                cache: false,
                dataType: 'json',
                url: '../handlers/AuthorityHandler.ashx?act=getsys&r=' + Math.random(),
                success: function (result) {
                    sysGrid.set('data', { Rows: result });
                }
            });
            function f_isChecked(rowdata) {
                if (rowdata.IsDel == "False") //未删除则是已开通
                    return true;
                return false;
            }


            //保存按钮
            function btnSaveClick() {
                var rowCorpSelected = corpGrid.getSelectedRows();
                if (rowCorpSelected.length == 0) {
                    alert("请选择企业！");
                    return;
                } else if (rowCorpSelected.length > 1) {
                    alert("只能选择一个企业！");
                    return;
                }

                var sysRows = sysGrid.getSelectedRows();
                var sysArr = [];
                for (var i = 0; i < sysRows.length; i++) {
                    sysArr.push(sysRows[i].KeyGuid);
                }
                var isrtUserGuid = "<%=isrtUserGuid %>";
                SaveCorpSys(rowCorpSelected[0].CorpUserGuid, sysArr.toString(), isrtUserGuid);
            }
            $("#btnSave").ligerButton(
            {
                text: '保存',
                click: btnSaveClick
            }
            );
            function SaveCorpSys(corpUserGuid, sysArr, isrtUserGuid) {
                $.ajax({
                    type: 'post',
                    cache: false,
                    data: { CorpInfo: corpUserGuid, SysInfo: sysArr, IsrtUserGuid: isrtUserGuid },
                    url: '../handlers/AuthorityHandler.ashx?act=dosaveuser&r=' + Math.random(),
                    success: function (result) {
                        alert(result);
                    }
                });
            }

            

        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="layout" style="margin: 2px; margin-right: 3px;">
        <div position="center" style="margin: 0 auto;" id="mainmenu" title="用户列表">
            <table cellpadding="0" cellspacing="0" style="margin: 2px auto auto 5px;" > 
                <tr>
                    <td align="right" >企业名称：</td>
                    <td style="width:200px" >
                        <input name="txtCorpName" type="text" id="txtCorpName" style="width:190px;" class="liger-textbox" /></td>
                    <td ><div style="margin: 5px auto;" id="btn"></div></td>
                </tr>
            </table>
            <div id="corpgrid" style="margin: 2px auto;">
            </div>
        </div>
        <div position="bottom" style="margin: 0 auto;" title="系统列表">
            <div id="sysgrid" style="margin: 2px auto;">
            </div>
            <div style="margin: 5px auto;" id="btnSave"></div>
        </div>
    </div>
</asp:Content>